home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr52 / pow_tb.zip / TBFILT2.PRG < prev    next >
Text File  |  1993-05-14  |  4KB  |  151 lines

  1.    /* tbFilt2.prg: Filtered browse of supplier.dbf.
  2.    
  3.    Builds an array of records that pass the filter criterion, and then
  4.    uses goTopBlock, goBottomBlock and skipBlock to display only the 
  5.    records whose record numbers are in the array.
  6.    
  7.    Copyright (C) Dave Boettcher 1993. This source code, and functional 
  8.    fragments thereof, may only be distributed unchanged and as part of 
  9.    the file POWER_TB.ARJ. See POWER_TB.TXT for full copyright details.
  10.  
  11.    Last change:  14 May 93       6:49 pm
  12.    */
  13.    
  14.    #include "setcurs.ch"
  15.    #include "inkey.ch"
  16.    #include "box.ch"
  17.    
  18. function main()
  19.    
  20.    local oBrowse
  21.    local oColumn
  22.    local nKey
  23.    local lCont := .T.
  24.    local oldColour := setcolor("w+/b")
  25.    local oldCursor := setcursor(SC_NONE)
  26.    
  27.    local currElement := 1
  28.    local maxElement := 0
  29.    local bScope := {|| alltrim(supplier->name) == "Nantucket UK Ltd"}
  30.    
  31.    use supplier new
  32.    
  33.    clear screen
  34.    @ 0, 0, 24, 79 box B_DOUBLE
  35.    
  36.    oBrowse := tbrowsedb(1, 1, 23, 78)
  37.    oBrowse:headsep   := "─┬─"
  38.    oBrowse:colsep    := " │ "
  39.    oBrowse:goBottomBlock := {|| dbgoto (oBrowse:cargo[1]), currElement := 1}
  40.    oBrowse:goTopBlock := {|| dbgoto (aTail(oBrowse:cargo)), currElement := maxElement}
  41.    oBrowse:skipBlock := {|n| skipper(n, oBrowse, @currElement, maxElement)}
  42.    oBrowse:cargo := {}
  43.    
  44.    if .not. eval(bScope)
  45.       do while .not. eval(bScope)
  46.          skip
  47.       enddo
  48.    endif
  49.    
  50.    do while eval(bScope) .and. !eof()
  51.       aadd(oBrowse:cargo, recno())
  52.       maxElement++
  53.       skip
  54.       do while .not. eval(bScope) .and. .not. eof()
  55.          skip
  56.       enddo
  57.    enddo
  58.    
  59.    dbgoto(oBrowse:cargo[1])
  60.    
  61.    oColumn := TBColumnNew("Name", {|| supplier->name})
  62.    oColumn:width := 30
  63.    oColumn:footsep := "─┴─"
  64.    oBrowse:AddColumn(oColumn)
  65.    
  66.    oColumn := TBColumnNew("Street", {|| supplier->street})
  67.    oColumn:width := 30 
  68.    oColumn:footsep := "─┴─"
  69.    oBrowse:AddColumn(oColumn)
  70.    
  71.    oColumn := TBColumnNew("Town", {|| supplier->town})
  72.    oColumn:width := 30
  73.    oColumn:footsep := "─┴─"
  74.    oBrowse:AddColumn(oColumn)
  75.    
  76.    oColumn := TBColumnNew("County", {|| supplier->county})
  77.    oColumn:width := 30
  78.    oColumn:footsep := "─┴─"
  79.    oBrowse:AddColumn(oColumn)
  80.    
  81.    oColumn := TBColumnNew("Postcode", {|| supplier->product})
  82.    oColumn:width := 7
  83.    oColumn:footsep := "─┴─"
  84.    oBrowse:AddColumn(oColumn)
  85.    
  86.    oColumn := TBColumnNew("Product", {|| supplier->product})
  87.    oColumn:width := 250
  88.    oColumn:footsep := "─┴─"
  89.    oBrowse:AddColumn(oColumn)
  90.    
  91.    
  92.    do while lCont
  93.       
  94.       //... Stabilize browse (until done, or keystroke hit)
  95.       do while .not. oBrowse:stable .AND. (nKey := InKey()) == 0
  96.          oBrowse:Stabilize()
  97.       enddo
  98.       
  99.       //... Everything stabilized
  100.       if oBrowse:stable
  101.          if (oBrowse:hitTop .OR. oBrowse:hitBottom)
  102.             Tone(125,0)
  103.          endif
  104.          nKey := InKey(0)
  105.       endif
  106.       
  107.       //... Handle keystrokes
  108.       Do Case
  109.          Case nKey == K_DOWN        ;  oBrowse:Down()
  110.          Case nKey == K_UP          ;  oBrowse:Up()
  111.          Case nKey == K_LEFT        ;  oBrowse:Left()
  112.          Case nKey == K_RIGHT       ;  oBrowse:Right()
  113.          Case nKey == K_PGDN        ;  oBrowse:PageDown()
  114.          Case nKey == K_PGUP        ;  oBrowse:PageUp()
  115.          Case nKey == K_CTRL_PGUP   ;  oBrowse:GoTop()
  116.          Case nKey == K_CTRL_PGDN   ;  oBrowse:GoBottom()
  117.          Case nKey == K_ESC         ;  lCont := .F.
  118.       endcase
  119.       
  120.    enddo
  121.    
  122.    setcolor(oldColour)
  123.    setcursor(oldCursor)
  124.    clear screen
  125.    
  126.    return nil
  127.    
  128.    
  129. function skipper(nRequest, oBrowse, currElement, maxElement)
  130.    
  131.    local nAllowed := 0
  132.    
  133.    do case
  134.          
  135.       case nRequest == 0
  136.          skip 0
  137.       case nRequest > 0
  138.          do while nAllowed < nRequest .and. currElement < maxElement
  139.             dbgoto(oBrowse:cargo[++currElement])
  140.             nAllowed++
  141.          enddo
  142.       case nRequest <0
  143.          do while nAllowed > nRequest .and. currElement > 1
  144.             dbgoto(oBrowse:cargo[--currElement])
  145.             nAllowed--
  146.          enddo
  147.          
  148.    endcase
  149.    
  150.    return nAllowed
  151.